package com.qh.service;

import java.util.Comparator;
import java.util.Objects;
import java.util.PriorityQueue;

/**
 * com.qh.service
 * 26832
 * yjj
 * &#064;description: 数据分析类的实现类
 * &#064;author: lxm
 * DataSysise
 * &#064;create: 2024-06-08 02:17
 **/

public class DataSysise implements DataSyscise {
    @Override
    public Object[] data(String[] allOptions) {
        double[] data = new double[13];
        String[] variableNames = {"龋病", "非龋性牙体组织损伤", "牙龈萎缩", "牙震荡", "牙脱位", "牙折", "楔状磨损", "牙本质过敏症", "四环素牙", "氟牙症", "牙髓炎", "根尖周炎", "慢性根尖周炎"};
        System.out.println("开始数据分析");
        double qubing = 0;//龋病概率
        double A2 =0;//非龋性牙体组织损伤概率
        double A3 =0;//计算牙龈萎缩概率
        double A4 =0;//计算牙震荡概率
        double A5 =0;//计算牙脱位概率
        double A6 =0;//计算牙折概率
        double A7 =0;//楔状磨损概率
        double A8 =0;//牙本质过敏症概率
        double A9 =0;//计算四环素牙概率
        double A10=0;//计算氟牙症概率
        double A11=0;//计算牙髓炎概率
        double A12=0;//计算根尖周炎概率
        double A13=0;//计算慢性根尖周炎概率
        //计算龋病概率
        for(String opton:allOptions){
            switch (opton){
                case "牙齿表面出现白色或黄褐色斑点":
                    qubing+=0.19;
                    System.out.println("牙齿表面出现白色或黄褐色斑点");
                    break;
                case "对酸甜冷热等外界刺激敏感":
                    qubing+=0.35;
                    System.out.println("对酸甜冷热等外界刺激敏感");
                    break;
                case "牙齿出现龋洞":
                    qubing+=0.46;
                    System.out.println("牙齿出现龋洞");
                    break;
            }
        }
        //计算非龋性牙体组织损伤概率
        for(String option:allOptions){
            if(option.equals("牙冠出现淡黄色")){
                A2+=1;
            }
        }
        //计算牙龈萎缩概率
        for(String option:allOptions){
            switch (option){
                case "牙龈出血":
                    A3+=0.12;
                    System.out.println("牙龈出血");
                    break;
                case "牙齿脱落":
                    A3+=0.17;
                    System.out.println("牙齿脱落");
                    break;
                case "牙齿有明显松动":
                    A3+=0.21;
                    System.out.println("牙齿有明显松动");
                    break;
                case "牙龈出现脓包":
                    A3+=0.34;
                    System.out.println("牙龈出现脓包");
                    break;
                case "口腔异味严重":
                    A3+=0.16;
                    System.out.println("口腔异味严重");
                    break;
            }
        }
        //计算牙震荡概率
        for(String option:allOptions){
            switch (option){
                case "牙龈出血":
                    A4+=0.12;
                    System.out.println("牙龈出血");
                    break;
                case "敲击牙齿产生异痛":
                    A4+=0.23;
                    System.out.println("敲击牙齿产生异痛");
                    break;
                case "牙齿轻微松动（摇晃不明显）":
                    A4+=0.22;
                    System.out.println("牙齿轻微松动（摇晃不明显）");
                    break;
                case "牙齿可伸长":
                    A4+=0.43;
                    System.out.println("牙齿可伸长");
                    break;
            }
        }
        //计算牙脱位概率
        for (String option:allOptions){
            if (option.equals("牙齿有明显松动")){
                A5+=0.43;
                System.out.println("牙齿有明显松动");
            } else if (option.equals("牙齿时常疼痛")) {
                A5+=0.57;
                System.out.println("牙齿时常疼痛");
            }
        }
        //计算牙折概率
        for (String option:allOptions){
            switch (option){
                case "牙齿可伸长":
                    A6+=0.26;
                    System.out.println("牙齿可伸长");
                    break;
                case "敲击牙齿产生异痛":
                    A6+=0.43;
                    System.out.println("敲击牙齿产生异痛");
                    break;
                case "牙齿有明显松动":
                    A6+=0.27;
                    System.out.println("牙齿有明显松动");
                    break;
                case "牙齿变色":
                    A6+=0.24;
                    System.out.println("牙齿变色");
                    break;
            }
        }
        //楔状磨损概率
        for(String option:allOptions){
            switch (option){
                case "牙体缺损":
                    A7+=0.46;
                    System.out.println("牙体缺损");
                    break;
                case "对酸甜冷热等外界刺激敏感":
                    A7+=0.22;
                    System.out.println("对酸甜冷热等外界刺激敏感");
                    break;
                case "牙齿有时疼痛":
                    A7+=0.32;
                    System.out.println("牙齿有时疼痛");
                    break;
            }
        }
        //牙本质过敏症概率
        for (String option:allOptions){
            if (option.equals("对酸甜冷热等外界刺激敏感")){
                A8+=1;
                System.out.println("对酸甜冷热等外界刺激敏感");
            }
        }
        //计算四环素牙病概率
        for (String option:allOptions){
            switch (option){
                case "牙齿表面发黄":
                    A9+=0.27;
                    System.out.println("牙齿表面发黄");
                    break;
                case "牙齿表面为黄褐色或棕色":
                    A9+=0.35;
                    System.out.println("牙齿表面为黄褐色或棕色");
                    break;
                case "牙齿表面为灰色或深紫色":
                    A9+=0.38;
                    System.out.println("牙齿表面为灰色或深紫色");
                    break;
            }
        }
        //计算氟牙症概率
        for (String option:allOptions){
            if (option.equals("牙齿表面有白垩色或棕色的对称性斑块")){
                A10+=0.67;
                System.out.println("牙齿表面有白垩色或棕色的对称性斑块");
            } else if (option.equals("牙体缺损")) {
                A10+=33;
                System.out.println("牙体缺损");
            }
        }
        //计算牙髓炎概率
        for (String option:allOptions){
            switch (option){
                case "牙齿时常疼痛":
                    A11+=0.24;
                    System.out.println("牙齿时常疼痛");
                    break;
                case "对酸甜冷热等外界刺激敏感":
                    A11+=0.13;
                    System.out.println("对酸甜冷热等外界刺激敏感");
                    break;
                case "牙齿咬合时产生异痛":
                    A11+=0.18;
                    System.out.println("牙齿咬合时产生异痛");
                    break;
                case "牙齿咬合时敏感——在下颌，头部等部位有异痛":
                    A11+=0.45;
                    System.out.println("牙齿咬合时敏感——在下颌，头部等部位有异痛");
                    break;
            }
        }
        //计算根尖周炎概率
        for (String option:allOptions){
           switch (option){
               case "牙齿咬合时产生异痛":
                   A12+=0.23;
                   System.out.println("牙齿咬合时产生异痛");
                   break;
               case "牙齿有时疼痛":
                   A12+=0.24;
                   System.out.println("牙齿有时疼痛");
                   break;
               case "牙龈肿胀":
                   A12+=0.16;
                   System.out.println("牙龈肿胀");
                   break;
           }
        }
        //计算慢性根尖周炎
        for (String option:allOptions){
            switch (option){
                case "牙龈出现脓包":
                    A13+=0.65;
                    System.out.println("牙龈出现脓包");
                    break;
                case "牙齿咬合时产生异痛":
                    A13+=0.35;
                    System.out.println("牙齿咬合时产生异痛");
                    break;
               }
           }
        data[0]=qubing;
        data[1]=A2;
        data[2]=A3;
        data[3]=A4;
        data[4]=A5;
        data[5]=A6;
        data[6]=A7;
        data[7]=A8;
        data[8]=A9;
        data[9]=A10;
        data[10]=A11;
        data[11]=A12;
        data[12]=A13;

        // 使用优先队列找到最大的三个值的索引
        PriorityQueue<Integer> maxIndices = new PriorityQueue<>(Comparator.comparingDouble(i -> -data[i]));
        for (int i = 0; i < data.length && maxIndices.size() < 3; i++) {
            maxIndices.offer(i);
        }

        // 创建二维数组，用于存储最大三个变量名及其对应的值
        Object[] result = new Object[6];
        for (int i = 0; i < 3; i++) {
            int index = maxIndices.poll();
            result[2 * i] = variableNames[index];
            result[2 * i + 1] = data[index];
        }

        return result;
    }

    @Override
    public boolean savedata(String[] allOptions) {
        return false;
    }
}
